<?php


namespace App\Service\Pay;


//use App\Service\WeChatPay\WeChatPayInterface;
use wechatPay\WeChatPay;

/**
 * 微信小程序和公众号支付
 * Create By Peter
 * 2019/12/27 13:17:07
 * Email:904801074@qq.com
 * Class Weapp
 * @package App\Service\Pay
 */
class Weapp implements PayInterface
{

    private $pay;

    function __construct()
    {

//        $this->pay=new Pay(env('WEAPP_APPID'),env('WECHATPAY_MCH_ID'),env('WECHATPAY_KEY'));


        $wechat=new WeChatPay(
            env('WEAPP_APPID'),
            env('WECHATPAY_MCH_ID'),
            env('WECHATPAY_KEY'),
            env('WECHATPAY_CERT_PATH'),
            env('WECHATPAY_KEY_PATH')
        );

        $this->pay=$wechat->getType('weapp');

    }



    function getParam($goods_dec,$out_trade_no,$money,$notify_url,$openid,$attach=''){


//        $data=$this->pay->for_jspay($goods_dec,$out_trade_no,$money,$openid,request()->ip(),$notify_url,$attach);

        $data=$this->pay->getPayParam($goods_dec,$out_trade_no,$money,request()->ip(),$notify_url,$openid,$attach);

//        $this->pay->


        return $data;
    }


    /**
     * 返回支付回复成功
     * Create by Peter
     * 2019/12/19 14:11:05
     * Email:904801074@qq.com
     * @return string
     */
    function replySuccess(){



        return '"<xml>
                <return_code><![CDATA[SUCCESS]]></return_code>
                <return_msg><![CDATA[OK]]></return_msg>
             </xml>"';
    }


    function checkPay(){


        return  $this->pay->check();

    }


    /**
     * 申请退款
     * Create by Peter
     * 2019/12/30 15:06:55
     * Email:904801074@qq.com
     * @param $transaction_id
     * @param $out_refund_no
     * @param $total_fee
     * @param $refund_fee
     * @param $notify_url
     * @return mixed
     */
    function refund($transaction_id,$out_refund_no,$total_fee,$refund_fee,$notify_url){

       return $this->pay->refund($transaction_id,$out_refund_no,$total_fee,$refund_fee,$notify_url);
    }


    /**
     * 退款通知
     * Create by Peter
     * 2019/12/30 16:57:17
     * Email:904801074@qq.com
     * @param null $data
     * @return mixed
     */
    function refund_check($data=null){


      return  $this->pay->check_refund($data);

    }



}
